/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.colegiatura.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import org.cip.esymons.colegiatura.beans.universidadController;
import org.cip.esymons.general.be.Universidad;

/**
 *
 * @author ADMINISTRADOR
 */
public class universidadConverter implements Converter {

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {

        if (arg2 == null) {
            return null;
        }

        Integer codigo = new Integer(arg2);
        universidadController controller = (universidadController) FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), "universidadController");
        return controller.buscaPorCodigo(codigo);
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {

        if (arg2 == null) {
            return null;
        }
        if (arg2 instanceof Universidad) {
            if (((Universidad) arg2).getUniCodigo() == null) {
                return null;
            } else {
                return ((Universidad) arg2).getUniCodigo().toString();
            }
        } else {
            return null;
        }
    }
}
